/**
 * 
 */
package org.myontology.users;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import model.Vocabulary;

import org.myontology.controller.AbstractAction;
import org.myontology.controller.AttributeHolder;
import org.myontology.controller.AttributeLevel;
import org.myontology.controller.SesameSession;
import org.myontology.controller.ValueHandler;
import org.openrdf.model.vocabulary.RDF;

/**
 * @author hacklm
 *
 */



public class ExportUsersAction extends AbstractAction {

	
	public static final ValueHandler<List<User>> EXPORT_USER = new ValueHandler<List<User>>(AttributeLevel.REQUEST,ExportUsersAction.class);
	
	private SesameSession session;
	
	/* (non-Javadoc)
	 * @see org.myontology.controller.Action#execute(org.myontology.controller.AttributeHolder)
	 */
	public void execute(AttributeHolder attributes) throws Exception {
		
		List<String> userNames = session.loadSubjectsByObject(RDF.TYPE, Vocabulary.USER);
		List<User> users = new ArrayList<User>();
		for (Iterator<String> it = userNames.iterator();it.hasNext();) {
			String userName = it.next();
			User user = new User();
			user.id.addValue(userName.substring(userName.lastIndexOf('/')+1));
			session.loadUser(user);
			users.add(user);
		}
		EXPORT_USER.setValue(attributes, users);
	}

}
